package com.example.demo.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.demo.db2.mapper.MyTableMapper2;
import com.example.demo.entity.MyTable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yfy2001
 * @date 2024/6/7 13:51
 */
@Service
@DS("mysql2")
public class MyTableService2 {

    @Resource
    private MyTableMapper2 myTableMapper2;

    public List<MyTable> getDataFromAllTablesById(Integer id) {
        List<MyTable> result = new ArrayList<>();
        String[] tables2 = {"ta1", "ta2", "ta3", "ta4", "ta5"};
        for (String table : tables2) {
            result.addAll(getData(table,id));
        }
        return result;
    }


    private List<MyTable> getData(String tableName,Integer id){
      return myTableMapper2.selectListFromTableById(tableName,id);
    }

    public int batchInsertData(String tableName,List<MyTable> data){
        return myTableMapper2.batchInsert(tableName,data);
    }

}